package pages;


import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class HomePage {


    private final String URL = "http://rozetka.com.ua/";

    public static WebDriver driver;

    @FindBy(how = How.ID, using = "computers-notebooks")
    protected WebElement project;

    @FindBy(how = How.ID, using = "phones-mp3-gps")
    protected WebElement phones;

    @FindBy(how = How.ID, using = "tv-photo-video")
    protected WebElement tvPhoto;

    @FindBy(how = How.ID, using = "bt")
    protected WebElement bt;

    @FindBy(how = How.ID, using = "outdoorsman")
    protected WebElement outdoorsman;

    @FindBy(how = How.ID, using = "kids")
    protected WebElement kids;

    @FindBy(how = How.ID, using = "house_garden")
    protected WebElement houseGarden;


    public HomePage(WebDriver driver) {
        this.driver = driver;
        PageFactory.initElements(driver, this);
    }

    public void open() {
        driver.get(URL);
    }

    public WebElement getClickablePageItem(WebElement menuItemElement) {
        WebDriverWait wait = new WebDriverWait(driver, 20);
        wait.until(ExpectedConditions.elementToBeClickable(menuItemElement));

        return menuItemElement;
    }

    public boolean isPageItemDisplayed(WebElement pageItem) {
        WebDriverWait wait = new WebDriverWait(driver, 20);
        wait.until(ExpectedConditions.elementToBeClickable(pageItem));

        return pageItem.isDisplayed();
    }

    public WebElement getProject() {
        return project;
    }

    public WebElement getPhones() {
        return phones;
    }

    public WebElement getTvPhoto() {
        return tvPhoto;
    }

    public WebElement getBt() {
        return bt;
    }

    public WebElement getOutdoorsman() {
        return outdoorsman;
    }

    public WebElement getKids() {
        return kids;
    }

    public WebElement getHouseGarden() {
        return houseGarden;
    }
}


